package cn.edu.nuc.ssm.dao;

import cn.edu.nuc.ssm.dto.BbsTopicAndUsername;
import cn.edu.nuc.ssm.entity.BbsTopic;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BbsTopicMapper {
    @Delete({
        "delete from bbs_topic",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into bbs_topic ( uid, ",
        "sid, reply_count, ",
        "title, content, ",
        "time, click_count)",
        "values ( #{uid,jdbcType=INTEGER}, ",
        "#{sid,jdbcType=INTEGER}, #{replyCount,jdbcType=INTEGER}, ",
        "#{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, ",
        "#{time,jdbcType=CHAR}, #{clickCount,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(BbsTopic record);

    int insertSelective(BbsTopic record);

    @Select({
        "select",
        "id, uid, sid, reply_count, title, content, time, click_count",
        "from bbs_topic",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("cn.edu.nuc.ssm.dao.BbsTopicMapper.BaseResultMap")
    BbsTopic selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(BbsTopic record);

    @Update({
        "update bbs_topic",
        "set uid = #{uid,jdbcType=INTEGER},",
          "sid = #{sid,jdbcType=INTEGER},",
          "reply_count = #{replyCount,jdbcType=INTEGER},",
          "title = #{title,jdbcType=VARCHAR},",
          "content = #{content,jdbcType=VARCHAR},",
          "time = #{time,jdbcType=CHAR},",
          "click_count = #{clickCount,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(BbsTopic record);


    BbsTopic findbyId(@Param("id")Integer id);

    List<BbsTopicAndUsername> findTopicAndUsername(@Param("sid") Integer sid);

    int countbySid(@Param("sid")Integer sid);

    List<BbsTopic> findbySid(@Param("sid")Integer sid);

    int deletebySid(@Param("sid")Integer sid);

    List<BbsTopic> find();

    int deletebyId(@Param("id")Integer id);


    void addCount(@Param("id")Integer id);

    int updateLocationbyId(@Param("updatedLocation")Integer updatedLocation,@Param("id")Integer id);

    List<BbsTopic> findbyLocationisnull();


    List<BbsTopic> findbyLocation(@Param("location")Integer location);

    int updatepicbyId(@Param("updatedPic")String updatedPic,@Param("id")Integer id);


    List<BbsTopic> findbyuid(@Param("uid")Integer uid);

//    id:$("#id").val(),
//    title: $("#title").val(),
//    content:ue.getPlainTxt(),
//    uid:$("#uid").val(),
//    sid:$("#sid").val()

    int updateTitleAndContentAnduidAndSidById(@Param("updatedTitle")String updatedTitle,@Param("updatedContent")String updatedContent,@Param("updatedUid")Integer updatedUid,@Param("updatedSid")Integer updatedSid,@Param("id")Integer id);


}